package com.rickpan.dto.zhipuai;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.List;

/**
 * 智谱AI API请求DTO
 */
public class ZhipuAIRequest {

    private String model;
    private Double temperature;
    
    @JsonProperty("top_k")
    private Integer topK;
    
    @JsonProperty("max_tokens")
    private Integer maxTokens;
    
    private List<ZhipuAIMessage> messages;

    // 构造函数
    public ZhipuAIRequest() {
        this.messages = new ArrayList<>();
    }

    // Builder模式
    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private String model = "glm-4-flash-250414";
        private Double temperature = 1.0;
        private Integer topK = 4;
        private Integer maxTokens = 20000;
        private List<ZhipuAIMessage> messages = new ArrayList<>();

        public Builder model(String model) {
            this.model = model;
            return this;
        }

        public Builder temperature(Double temperature) {
            this.temperature = temperature;
            return this;
        }

        public Builder topK(Integer topK) {
            this.topK = topK;
            return this;
        }

        public Builder maxTokens(Integer maxTokens) {
            this.maxTokens = maxTokens;
            return this;
        }

        public Builder messages(List<ZhipuAIMessage> messages) {
            this.messages = messages;
            return this;
        }

        public Builder addMessage(String role, String content) {
            this.messages.add(new ZhipuAIMessage(role, content));
            return this;
        }

        public Builder addSystemMessage(String content) {
            return addMessage("system", content);
        }

        public Builder addUserMessage(String content) {
            return addMessage("user", content);
        }

        public ZhipuAIRequest build() {
            ZhipuAIRequest request = new ZhipuAIRequest();
            request.model = this.model;
            request.temperature = this.temperature;
            request.topK = this.topK;
            request.maxTokens = this.maxTokens;
            request.messages = this.messages;
            return request;
        }
    }

    // Getter 和 Setter 方法
    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public Double getTemperature() {
        return temperature;
    }

    public void setTemperature(Double temperature) {
        this.temperature = temperature;
    }

    public Integer getTopK() {
        return topK;
    }

    public void setTopK(Integer topK) {
        this.topK = topK;
    }

    public Integer getMaxTokens() {
        return maxTokens;
    }

    public void setMaxTokens(Integer maxTokens) {
        this.maxTokens = maxTokens;
    }

    public List<ZhipuAIMessage> getMessages() {
        return messages;
    }

    public void setMessages(List<ZhipuAIMessage> messages) {
        this.messages = messages;
    }

    @Override
    public String toString() {
        return "ZhipuAIRequest{" +
                "model='" + model + '\'' +
                ", temperature=" + temperature +
                ", topK=" + topK +
                ", maxTokens=" + maxTokens +
                ", messages=" + messages +
                '}';
    }
}
